package com.bsh.controller.account;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.bsh.dto.AccountNoticeQryDto;
import com.bsh.dto.UserEditDto;
import com.bsh.service.AccountStateService;
import com.bsh.utils.KeyValuePair;

/**
 * 账户资金统计
 * @author gsh
 *
 */
@Controller
public class AccountStateController {
	private static Logger log = LoggerFactory.getLogger(AccountStateController.class);

	@Autowired
	HttpServletRequest request;
	@Autowired
	HttpServletResponse response;
	@Autowired
	AccountStateService servState;

	/**
	 * 资金统计
	 */
	@RequestMapping(value = "/account/notice/state")
	public ModelAndView noticeStateList(@ModelAttribute AccountNoticeQryDto dto) {
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		if(dto==null|| dto.getIsFirst()==null){
		  dto=new AccountNoticeQryDto();
		  Calendar cal=Calendar.getInstance();
		  cal.setTime(new Date());	
		  cal.add(Calendar.DAY_OF_MONTH,0);
		  dto.setCreateTime(sdf.format(cal.getTime()));
		  
		  Calendar cal2=Calendar.getInstance();
		  cal2.setTime(new Date());
		  cal2.add(Calendar.DAY_OF_MONTH,0);		  
		  dto.setCreateTime1(sdf.format(cal2.getTime()));
		  
		}
		
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/pages/account/noticeState");
		Map<String,Object> sysStates = servState.getSysStates();
		List<KeyValuePair<String,String>> list = servState.getStates(dto.getCreateTime(),dto.getCreateTime1());
		mv.addObject("sys",sysStates);
		mv.addObject("data",list);
		mv.addObject("isFirst","0");
		mv.addObject("dto", dto==null?new UserEditDto():dto);
		return mv;
	}
}
